home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 501-525 / disk_503 / pcq / pcq12a.lzh / Examples / Dry.p < prev    next >
Text File  |  1991-03-29  |  7KB  |  352 lines

  1. Program Dhrystone;
  2.  
  3. {
  4.     This is the Dhrystone benchmark program, used to judge the
  5. efficiency of a realistic mix of instruction types.  That mix is
  6. approximately  53% assignments, 32% control statements, and 15%
  7. procedure and function calls.  Apparently by some measure that's
  8. typical.  It also attempts to balance statement types, operand
  9. types, and operand access (global, local, etc).
  10.  
  11.     The original benchmark was written by Reinhold P. Weicker for
  12. CACM Volume 27, Number 10, 10/84 p. 1013.  That program was in
  13. Ada, but the version I used was a translation to C by Rick
  14. Richardson, from Fred Fish disk #1.
  15.  
  16.     I translated this program to get a general sense of how PCQ
  17. stacks up against other compilers for the Amiga.  I got (on my
  18. 25MHz Amiga 3000) just under 4000 dhrystones/second in Pascal, and
  19. about 4500 dhrystones/second for DICE, which is actually closer
  20. than I expected.  Never put too much faith in benchmarks, however.
  21. }
  22.  
  23.  
  24. {$I "Include:Utils/TimerUtils.i"}
  25. {$I "Include:Devices/Timer.i"}
  26. {$I "Include:Utils/StringLib.i"}
  27.  
  28. { Accuracy of timings and human fatigue controlled by next two lines }
  29.  
  30. Const
  31.     LOOPS   = 50000;        { Use this for slow or 16 bit machines }
  32.  
  33. { Compiler dependent options }
  34.  
  35.     HZ      = 100;        { For the Time function below }
  36.  
  37.  
  38. Type
  39.     Enumeration = (Ident1, Ident2, Ident3, Ident4, Ident5);
  40.  
  41.     OneToThirty   = Integer;
  42.     OneToFifty    = Integer;
  43.     CapitalLetter = Char;
  44.     String30      = Array [0..30] of Char;
  45.     Array1Dim     = Array [0..51] of Integer;
  46.     Array2Dim     = Array [0..51,0..51] of Integer;
  47.  
  48.     RecordStruct = record
  49.     PtrComp     : ^RecordStruct;
  50.     Discr       : Enumeration;
  51.         EnumComp    : Enumeration;
  52.         IntComp     : OneToFifty;
  53.         StringComp  : String30;
  54.     end;
  55.  
  56.     RecordType   = RecordStruct;
  57.     RecordPtr    = ^RecordType;
  58.  
  59.  
  60.  
  61. { * Package 1 }
  62.  
  63. Var
  64.     IntGlob    : Integer;
  65.     BoolGlob    : Boolean;
  66.     Char1Glob    : Char;
  67.     Char2Glob    : Char;
  68.     Array1Glob    : Array1Dim;
  69.     Array2Glob    : Array2Dim;
  70.     PtrGlb    : RecordPtr;
  71.     PtrGlbNext    : RecordPtr;
  72.  
  73.     Timer    : TimeRequestPtr;
  74.  
  75. {  Return system time in hundreths of a second }
  76.  
  77. Function Time : Integer;
  78. var
  79.     TV : TimeVal;
  80. begin
  81.     GetSysTime(Timer,TV);
  82.     with TV do
  83.     Time := tv_Secs * 100 + tv_Micro div 10000;
  84. end;
  85.  
  86.  
  87.  
  88. Function Func1(CharPar1, CharPar2 : CapitalLetter) : Enumeration;
  89. var
  90.     CharLoc1    : CapitalLetter;
  91.     CharLoc2    : CapitalLetter;
  92. begin
  93.     CharLoc1 := CharPar1;
  94.     CharLoc2 := CharLoc1;
  95.     if CharLoc2 <> CharPar2 then
  96.     Func1 := Ident1
  97.     else
  98.     Func1 := Ident2;
  99. end;
  100.  
  101.  
  102.  
  103. Function Func2(var StrParI1, StrParI2 : String30) : Boolean;
  104. var
  105.     IntLoc    : OneToThirty;
  106.     CharLoc    : CapitalLetter;
  107. begin
  108.     IntLoc := 1;
  109.     while IntLoc <= 1 do
  110.     if Func1(StrParI1[IntLoc], StrParI2[IntLoc+1]) = Ident1 then begin
  111.         CharLoc := 'A';
  112.         Inc(IntLoc);
  113.     end;
  114.  
  115.     if (CharLoc >= 'W') and (CharLoc <= 'Z') then
  116.     IntLoc := 7;
  117.  
  118.     if CharLoc = 'X' then
  119.     Func2 := True
  120.     else begin
  121.     if strcmp(Adr(StrParI1), Adr(StrParI2)) > 0 then begin
  122.         IntLoc := IntLoc + 7;
  123.         Func2 := True;
  124.     end else
  125.         Func2 := False;
  126.     end;
  127. end;
  128.  
  129.  
  130.  
  131. Function Func3(EnumParIn : Enumeration) : Boolean;
  132. var
  133.     EnumLoc    : Enumeration;
  134. begin
  135.     EnumLoc := EnumParIn;
  136.     if EnumLoc = Ident3 then
  137.     Func3 := True;
  138.     Func3 := False;
  139. end;
  140.  
  141.  
  142.  
  143. Procedure Proc8(var Array1Par : Array1Dim;
  144.         var Array2Par : Array2Dim;
  145.         IntParI1, IntParI2 : OneToFifty);
  146. var
  147.     IntLoc    : OneToFifty;
  148.     IntIndex    : OneToFifty;
  149. begin
  150.     IntLoc := IntParI1 + 5;
  151.     Array1Par[IntLoc] := IntParI2;
  152.     Array1Par[IntLoc+1] := Array1Par[IntLoc];
  153.     Array1Par[IntLoc+30] := IntLoc;
  154.  
  155.     for IntIndex := IntLoc to IntLoc + 1 do
  156.     Array2Par[IntLoc,IntIndex] := IntLoc;
  157.  
  158.     Inc(Array2Par[IntLoc,IntLoc-1]);
  159.     Array2Par[IntLoc+20,IntLoc] := Array1Par[IntLoc];
  160.     IntGlob := 5;
  161. end;
  162.  
  163.  
  164.  
  165. Procedure Proc7(IntParI1, IntParI2 : OneToFifty;
  166.         var IntParOut : OneToFifty);
  167. var
  168.     IntLoc    : OneToFifty;
  169. begin
  170.     IntLoc := IntParI1 + 2;
  171.     IntParOut := IntParI2 + IntLoc;
  172. end;
  173.  
  174.  
  175.  
  176. Procedure Proc6(EnumParIn : Enumeration; var EnumParOut : Enumeration);
  177. begin
  178.     EnumParOut := EnumParIn;
  179.     if not Func3(EnumParIn) then
  180.     EnumParOut := Ident4;
  181.     case EnumParIn of
  182.       Ident1    : EnumParOut := Ident1;
  183.       Ident2    : if IntGlob > 100 then
  184.               EnumParOut := Ident1
  185.           else
  186.               EnumParOut := Ident4;
  187.       Ident3    : EnumParOut := Ident2;
  188.       Ident4    : ;
  189.       Ident5    : EnumParOut := Ident3;
  190.     end;
  191. end;
  192.  
  193.  
  194.  
  195. Procedure Proc5;
  196. begin
  197.     Char1Glob := 'A';
  198.     BoolGlob  := FALSE;
  199. end;
  200.  
  201.  
  202.  
  203. Procedure Proc4;
  204. var
  205.     BoolLoc    : Boolean;
  206. begin
  207.     BoolLoc := Char1Glob = 'A';
  208.     BoolLoc := BoolLoc or BoolGlob;
  209.     Char2Glob := 'B';
  210. end;
  211.  
  212.  
  213.  
  214. Procedure Proc3(var PtrParOut : RecordPtr);
  215. begin
  216.     if PtrGlb <> Nil then
  217.         PtrParOut := PtrGlb^.PtrComp
  218.     else
  219.         IntGlob := 100;
  220.     Proc7(10, IntGlob, PtrGlb^.IntComp);
  221. end;
  222.  
  223.  
  224.  
  225. Procedure Proc2(var IntParIO : OneToFifty);
  226. var
  227.     IntLoc    : OneToFifty;
  228.     EnumLoc    : Enumeration;
  229. begin
  230.     IntLoc := IntParIO + 10;
  231.     while true do begin
  232.     if Char1Glob = 'A' then begin
  233.         Dec(IntLoc);
  234.         IntParIO := IntLoc - IntGlob;
  235.         EnumLoc := Ident1;
  236.     end;
  237.     if EnumLoc = Ident1 then
  238.         return;
  239.     end;
  240. end;
  241.  
  242.  
  243.  
  244. Procedure Proc1(PtrParIn : RecordPtr);
  245. begin
  246.     with PtrParIn^ do begin
  247.     PtrComp^ := PtrGlb^;
  248.     IntComp  := 5;
  249.     PtrComp^.IntComp := IntComp;
  250.     PtrComp^.PtrComp := PtrComp;
  251.     Proc3(PtrComp^.PtrComp);
  252.  
  253.     if PtrComp^.Discr = Ident1 then begin
  254.         PtrComp^.IntComp := 6;
  255.         Proc6(EnumComp, PtrComp^.EnumComp);
  256.         PtrComp^.PtrComp := PtrGlb^.PtrComp;
  257.         Proc7(PtrComp^.IntComp, 10, PtrComp^.IntComp);
  258.     end else
  259.         PtrParIn^ := PtrComp^;
  260.     end;
  261. end;
  262.  
  263.  
  264.  
  265. Procedure Proc0;
  266. var
  267.     IntLoc1    : OneToFifty;
  268.     IntLoc2    : OneToFifty;
  269.     IntLoc3    : OneToFifty;
  270.     CharLoc    : Char;
  271.     CharIndex    : Char;
  272.     EnumLoc    : Enumeration;
  273.     String1Loc  : String30;
  274.     String2Loc  : String30;
  275.     i        : Integer;
  276.  
  277.     starttime    : Integer;
  278.     benchtime    : Integer;
  279.     nulltime    : Integer;
  280.  
  281. begin
  282.     Timer := CreateTimer;
  283.     if Timer = Nil then
  284.     return;
  285.  
  286.     starttime := Time;
  287.  
  288.     for i := 1 to LOOPS do ;
  289.  
  290.     nulltime := Time - starttime;    { Computes overhead of looping }
  291.  
  292.     New(PtrGlbNext);
  293.     New(PtrGlb);
  294.  
  295.     PtrGlb^.PtrComp  := PtrGlbNext;
  296.     PtrGlb^.Discr    := Ident1;
  297.     PtrGlb^.EnumComp := Ident3;
  298.     PtrGlb^.IntComp  := 40;
  299.     strcpy(Adr(PtrGlb^.StringComp), "DHRYSTONE PROGRAM, SOME STRING");
  300.  
  301. {****************
  302. -- Start Timer --
  303. ****************}
  304.  
  305.     Writeln('Start timer!');
  306.     starttime := Time;
  307.  
  308.     for i := 0 to Pred(Loops) do begin
  309.     Proc5;
  310.     Proc4;
  311.     IntLoc1 := 2;
  312.     IntLoc2 := 3;
  313.     strcpy(Adr(String2Loc), "DHRYSTONE PROGRAM, 2'ND STRING");
  314.  
  315.     EnumLoc := Ident2;
  316.     BoolGlob := not Func2(String1Loc, String2Loc);
  317.  
  318.     while IntLoc1 < IntLoc2 do begin
  319.         IntLoc3 := 5 * IntLoc1 - IntLoc2;
  320.         Proc7(IntLoc1, IntLoc2, IntLoc3);
  321.         Inc(IntLoc1);
  322.     end;
  323.  
  324.     Proc8(Array1Glob, Array2Glob, IntLoc1, IntLoc3);
  325.     Proc1(PtrGlb);
  326.     for CharIndex := 'A' to Char2Glob do
  327.         if EnumLoc = Func1(CharIndex, 'C') then
  328.         Proc6(Ident1, EnumLoc);
  329.     IntLoc3 := IntLoc2 * IntLoc1;
  330.     IntLoc2 := IntLoc3 div IntLoc1;
  331.     IntLoc2 := 7 * (IntLoc3 - IntLoc2) - IntLoc1;
  332.     Proc2(IntLoc1);
  333.  
  334.     end;
  335.  
  336. {****************
  337. -- Stop Timer --
  338. ****************}
  339.     Writeln('Stop timer!');
  340.  
  341.     benchtime := (Time - starttime) - nulltime;
  342.  
  343.     Writeln('Dhrystone time for ', LOOPS, ' passes = ',
  344.         benchtime div HZ, ' seconds');
  345.     Writeln('This benchmarks at ', LOOPS * HZ div benchtime, ' dhrystones/second');
  346. end;
  347.  
  348.  
  349. begin
  350.    Proc0;
  351. end.
  352.